//
//  WithDrawalView.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/5.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "WithDrawalView.h"
#import "UILabel+YBAttributeTextTapAction.h"

@interface WithDrawalView ()<YBAttributeTapActionDelegate>
{
    GLGWLabel *tipLab;
}
@end

@implementation WithDrawalView

- (id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView
{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];

        GLGWView *liView = [[GLGWView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(10)) inSuperView:self];
        liView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        
        GLGWView *midelView = [[GLGWView alloc] initWithInSuperView:self];
        midelView.backgroundColor = [UIColor whiteColor];
        [midelView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(liView.mas_bottom);
            make.left.right.equalTo(self);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(138)));
        }];
        
        GLGWLabel *lab1 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:midelView];
        [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(midelView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.top.equalTo(midelView.mas_top).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
        }];
        lab1.text = @"提现金额";
        
        GLGWLabel *lab2 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12.5) theColor:kColor_Rule_Black inSuperView:midelView];
        [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lab1.mas_left);
            make.top.equalTo(lab1.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(9));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(36)));
        }];
        lab2.text = @"￥";
        
        GLGWButton *allWithDrawBtn = [[GLGWButton alloc] initWithTitle:@"全部提现" titleLableFont:SYSTEMFONT(16) titleLableColor:[UIColor colorWithHexString:@"#A89A60"] inSuperView:midelView];
        [allWithDrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(midelView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.centerY.equalTo(lab2.mas_centerY);
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(79)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
        }];
//        [allWithDrawBtn setBackgroundColor:kRandomColor];
        [allWithDrawBtn addTarget:self action:@selector(withAllDrawAction:) forControlEvents:UIControlEventTouchUpInside];
        
        GLGWTextField *textField = [[GLGWTextField alloc] initTitlePlaceholder:@"请输入提现金额" theFont:SYSTEMFONT(25) theTitColor:kColor_Rule_Black inSuperView:midelView];
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(allWithDrawBtn.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(6));
            make.left.equalTo(lab2.mas_right).offset(kWidthProportion_In_iPhoneTriploid(7));
            make.centerY.equalTo(lab2.mas_centerY);
            make.height.equalTo(lab2);
        }];
        NSString *holderText = @"请输入提现金额";
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
        [placeholder addAttribute:NSForegroundColorAttributeName
                            value:[UIColor colorWithHexString:@"#C4C4C4"]
                            range:NSMakeRange(0, holderText.length)];
        [placeholder addAttribute:NSFontAttributeName
                            value:[UIFont systemFontOfSize:16]
                            range:NSMakeRange(0, holderText.length)];
        textField.attributedPlaceholder = placeholder;
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.returnKeyType = UIReturnKeySearch;
        textField.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField = textField;
        
        GLGWLabel *lab3 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:midelView];
        [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lab2.mas_left);
            make.top.equalTo(lab2.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(12));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        lab3.text = @"可提现金额0.00元";
        tipLab = lab3;
        
        GLGWButton *withDrawBtn = [[GLGWButton alloc] initWithTitle:@"申请提现" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor colorWithHexString:@"#FFFFFF"] inSuperView:self];
        [withDrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(midelView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(48));
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15));
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(44)));
        }];
        [withDrawBtn setBackgroundImage:[UIImage imageWithStartColor:[UIColor colorWithHexString:@"#A89A60" alpha:1] endColor:[UIColor colorWithHexString:@"#A89A60" alpha:0.8]] forState:UIControlStateNormal];
        withDrawBtn.backgroundColor = [UIColor colorWithHexString:@"#D8D8D8"];
        withDrawBtn.layer.masksToBounds = YES;
        withDrawBtn.layer.cornerRadius = kHeightProportion_In_iPhoneTriploid(22);
        self.withDrawBtn = withDrawBtn;        
        
        GLGWLabel *lab4 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self];
        [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(kWidthProportion_In_iPhoneTriploid(38));
            make.top.equalTo(withDrawBtn.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(20));
        }];
        NSString *labStr = @"您还未完成实名认证，无法提现！ 去实名认证";
        NSRange rang = [labStr rangeOfString:@"去实名认证"];
        NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc]initWithString:labStr];
        [attributedString2 addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:NSMakeRange(0, labStr.length)]; //字号
        [attributedString2 addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#A89A60"] range:rang]; //点击的文字
        lab4.attributedText = attributedString2;
        lab4.userInteractionEnabled = YES;
        
        kWeakSelf(self);
        [lab4 yb_addAttributeTapActionWithStrings:@[@"去实名认证"] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            if ([string isEqualToString:@"去实名认证"]) {
                DLog(@"去实名认证");
                if (weakself.BlockTapLab) {
                    weakself.BlockTapLab(string);
                }
            }
        }];        
    }
    return self;
}

- (void)setWithDrawBtn:(GLGWButton *)withDrawBtn
{
    _withDrawBtn = withDrawBtn;
}

- (void)tipStr:(NSString *)str colorStr:(NSString *)colorStr
{
    tipLab.text = str;
    tipLab.textColor = [UIColor colorWithHexString:colorStr];
}

- (void)withAllDrawAction:(GLGWButton *)sender
{
    if (self.BlockAllWithDraw) {
        self.BlockAllWithDraw(sender);
    }
    
}
- (void)withDrawAction:(GLGWButton *)sender
{
    
}
@end
